#ifndef FAVORITESMODEL_H
#define FAVORITESMODEL_H
#include <QAbstractItemModel>
#include <QFont>

namespace ExecTerminalImplNS
{
    class AbstractFavoritesItem;
    class FolderFavoritesItem;
    extern const char * const MODEL_MIME_TYPE;
    class FavoritesModel: public QAbstractItemModel
    {
    public:
        FavoritesModel(QObject *parent = 0);
        ~FavoritesModel();

        //model access interface
        QVariant data(const QModelIndex &index, int role = Qt::DisplayRole)const;
        Qt::ItemFlags flags(const QModelIndex &index)const;
        QVariant headerData(int section,  Qt::Orientation orientation, int role = Qt::DisplayRole)const;
        QModelIndex index(int row,  int column = 0, const QModelIndex &parent = QModelIndex())const;
        QModelIndex parent(const QModelIndex &index)const;
        int rowCount(const QModelIndex &parent = QModelIndex())const;
        int columnCount(const QModelIndex &parent = QModelIndex())const;
        Qt::DropActions supportedDropActions()const;
        QStringList mimeTypes()const;
        QMimeData *mimeData(const QModelIndexList &indexes)const;

        //model editing interface
        bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
        void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
        bool removeRows(int row, int count, const QModelIndex & parent);
        bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent);

        //my interface
        AbstractFavoritesItem * itemFromIndex(const QModelIndex & indx = QModelIndex())const;

        void addFolder(const QString & name, QModelIndex parent = QModelIndex());
        void addItem(const QString & name, 
            const QString & url, 
            const QPixmap & icon, 
            QModelIndex parent = QModelIndex());

        QFont folderFont()const;
        void setFolderFont(const QFont & aFont);

        
        QByteArray getInternalState()const;
        void restoreInternalState(const QByteArray &);

        QString getFullItemPath(QModelIndex index)const;
        bool isFolderIndex(const QModelIndex & index)const;

    private:
        void writeToDataStream(QDataStream & out)const;
        void readFromDataStream(QDataStream & in);
        void insertItemToList(AbstractFavoritesItem * item, int pos, const QModelIndex & parent);
        void recursiveSortFolderChildren(FolderFavoritesItem * folderItem, Qt::SortOrder order);

    private:
        FolderFavoritesItem * theRootItem;
        QFont theFolderFont;
        mutable QPersistentModelIndex theCurrentDragIndex;
    };
}

#endif

